package com.dw.demo.consumer.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;


/**
 * 配置公共中间跳跃方法
 */
@Component
public class RestTemplateService {
    @Autowired
    @LoadBalanced
    private RestTemplate loadBalanced;

    @Autowired
    RestTemplate restTemplate;

    public String hiService() {
        loadBalanced.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
        return loadBalanced.getForObject("http://service-client/demo",String.class);
    }


    public String checkLogin(String account,String password) {
        loadBalanced.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
        return loadBalanced.getForObject("http://service-client/checkLogin",String.class);
    }

    public String returnBaidu() {
        restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
        return restTemplate.getForObject("https://www.baidu.com",String.class);
    }

    public String returnHao123() {
        restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
        return restTemplate.getForObject("https://www.hao123.com",String.class);
    }
}
